﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Web;
using System.Web.Mvc;
using BuySoftwareOnline.Domain.Abstract;
using BuySoftwareOnline.Domain;
using BuySoftwareOnline.Web.Models;
using BuySoftwareOnline.Domain.Concrete;

namespace BuySoftwareOnline.Web.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        private IProductRepository pRepository;
        private IAdvertiseRepository aRepository;

        public HomeController()
        {
            pRepository = new ProductRepository();
            aRepository = new AdvertiseRepository();
        }

        public ActionResult Index()
        {
            return View();
        }

        public PartialViewResult Advertise()
        {
            return PartialView();
        }

        public PartialViewResult TopProduct()
        {
            ProductsListViewModel topproduct = new ProductsListViewModel
            {
                TopProducts = pRepository.Products.OrderByDescending(p => p.TotalOrder).Select(p => p).Take(5),
                NewProducts = pRepository.Products.OrderByDescending(c => c.CreateTime).Select(c => c).Take(5)
            };
            return PartialView(topproduct);
        }
    }
}
